package com.xiaohudie.Ioliu;

import org.junit.jupiter.api.Test;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * @Author xiao hu die
 * @Date 2022/1/8 17:53
 * @Version 1.0
 */
/**bufferInputStream
 * 字节流可以操作所有文件二进制和文本文件都行*/
public class Test04 {
    public static void main(String[] args) {

    }
  @Test
    public  void test01() throws Exception{
        String path ="D:\\微信图片_20220102172232.jpg";
        String mianPath="D:\\图片1.jpg";
      BufferedOutputStream bufferedOutputStream =null;
      BufferedInputStream bufferedInputStream =null;
   bufferedInputStream =  new BufferedInputStream(new FileInputStream(path));
   bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mianPath));
   /**循环的读取文件并写入 */
   /**这是一次读取的字节数*/
   byte[] bytes =new byte[1024];
   int readLine =0;
   /**循环读取文件，当等于-1时就表示读取完毕了*/
   while ( (readLine =bufferedInputStream.read(bytes)) !=-1){
       bufferedOutputStream.write(bytes,0,readLine);
   }
   bufferedInputStream.close();
   bufferedOutputStream.close();
    }
}
